import * as Cesium from "cesium";
import gsap from "gsap";
export default class HexaGonMaterial {
  constructor(name) {
    this.name = name;
    // 实现属性
    this.definitionChanged = new Cesium.Event();
    Cesium.Material._materialCache.addMaterial("HexaGonMaterial", {
      fabric: {
        type: "HexaGonMaterial",
        uniforms: {
          uTime: 0,
          uImage: "/texture/hexagon.png",
        },
        source: `
          czm_material czm_getMaterial(czm_materialInput materialInput){
            // 生成默认材质
            czm_material material = czm_getDefaultMaterial(materialInput);
            // st 
            vec2 st = materialInput.st;
            // 纹理采样
            vec4 color = texture2D(uImage,st);
            // 给默认材质图案
            material.diffuse = color.rgb;
            material.alpha = color.a;
            return material;
          }
        `,
      },
    });
    this.params = {
      uTime: 0,
    };
    gsap.to(this.params, {
      uTime: 1,
      repeat: -1,
      yoyo: true,
      duration: 1,
    });
  }
  getType() {
    return "HexaGonMaterial";
  }
  getValue(time, result) {
    result.uTime = this.params.uTime;
    return result;
  }
  equals(other) {
    return other instanceof HexaGonMaterial && this.name == other.name;
  }
}
